package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference
    private SetmealService setmealService;


     //查询所有套餐信息,封装成套餐集合,返回到前台套餐列表页面,显示所有套餐
    @RequestMapping("/getSetmeal")
    public Result getSetmeal() {

        try {
            List<Setmeal> setmealList = setmealService.findAllSetmeal();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    //根据套餐Id查询其基本信息,和关联的所有检查组,检查项信息,返回到套餐详情页面
    @RequestMapping("/findAllsBySetmealId")
    public Result findAllsBySetmealId(Integer setmealId) {

        try {
            Setmeal setmeal = setmealService.findAllsBySetmealId(setmealId);
            System.out.println(setmeal);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    //根据套餐Id查询套餐的基本信息,返回到前台预约页面

    @RequestMapping("/findSetmealById")
    public Result findSetmealBySetmealId(Integer setmealId){

        try {
            Setmeal setmeal = setmealService.findSetmealBySetmealId(setmealId);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }

    }
}
